package com.demo01.client;

import com.demo01.core.HelloPacket;
import com.demo01.core.RuiSingPacket;
import com.demo01.server.utils;
import org.tio.client.ClientChannelContext;
import org.tio.client.ClientTioConfig;
import org.tio.client.ReconnConf;
import org.tio.client.TioClient;
import org.tio.client.intf.ClientAioHandler;
import org.tio.client.intf.ClientAioListener;
import org.tio.core.Node;
import org.tio.core.Tio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author qianyingchao
 * @version 1.0
 * @date 2021/5/24 12:36 下午
 */
public class Client {



    public static void send_message(String data) throws Exception {
        Node serverNode = new Node("211.159.224.10", 8777);
        ReconnConf reconnConf = new ReconnConf(5000000L);
        ClientAioHandler clientHandler = new ClientDemoHandler();
        ClientAioListener clientListener = new ClientDemoListener();
        ClientTioConfig clientTioConfig = new ClientTioConfig(clientHandler, clientListener, reconnConf);
        clientTioConfig.setHeartbeatTimeout(5000000);
        TioClient tioClient = new TioClient(clientTioConfig);
        ClientChannelContext clientChannelContext = tioClient.connect(serverNode);


        HelloPacket DataPacket = new HelloPacket();
        DataPacket.setBody(data.getBytes(StandardCharsets.UTF_8));
        Tio.send(clientChannelContext, DataPacket);

    }

    public static void main(String[] args) throws Exception {

        ArrayList<String> messages = new ArrayList<>();
        messages.add("usr.cnAT+IMEI");
        messages.add("usr.cnAT+ICCID");
        messages.add("usr.cnAT+LBS");
        messages.add("usr.cnAT+CSQ");
        for (String message : messages) {
            send_message(message);
        }






    }


}
